package com.netty.messagepack;


import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

public class EchoServerHandler extends ChannelHandlerAdapter {

    /**
     * 当异常发生时
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        //super.exceptionCaught(ctx, cause);
        ctx.close();
    }
    /**
     * 读取缓冲区里面的数据，处理并返回
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        List<UserInfo> userInfo = (List<UserInfo>) msg;
        System.out.println("server receive message from client =" + userInfo);
        ctx.writeAndFlush(userInfo);
    }
}

